package top.buluoluo.userservice.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.buluoluo.commoncore.domain.response.Result;
import top.buluoluo.userservice.dto.request.RegisterRequest;
import top.buluoluo.userservice.dto.request.UserAddressPageRequst;
import top.buluoluo.userservice.dto.response.UserDTO;
import top.buluoluo.userservice.dto.result.PageResult;
import top.buluoluo.userservice.entity.UserAddress;
import top.buluoluo.userservice.service.UserService;

@RestController
@RequestMapping("/users")
@Tag(name = "用户管理", description = "用户注册、获取用户信息相关接口") // 为控制器添加标签和描述
public class UserController {
    @Autowired
    private UserService userService;

    @Operation(summary = "注册接口", description = "接受前端的注册表为RegisterRequest对象，成功则返回用户信息")
    @PostMapping("/register")
    public Result<UserDTO> register(@RequestBody @Valid RegisterRequest registerRequest) {
        return userService.register(registerRequest);
    }
    @Operation(summary = "分页获取用户收货地址接口", description = "接受前端的userId和分页信息")
    @PostMapping("/getUserAddress")
    public Result<PageResult<UserAddress>> register(@RequestBody UserAddressPageRequst userAddressPageRequst) {
        return userService.getUserAddresses(userAddressPageRequst);
    }
    @Operation(summary = "获取默认用户收货地址接口", description = "获取用户id对应的默认收货地址")
    @GetMapping("/getDefaultUserAddress/{userId}")
    public Result<UserAddress> register(@PathVariable Long userId) {
        return userService.getDefaultUserAddress(userId);
    }

}
